package com.example.a2007dou_shop.net

import com.blankj.utilcode.util.SPUtils
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import java.util.concurrent.TimeUnit

class RetrofitUtils {
    companion object{
        val client = OkHttpClient.Builder()
            .readTimeout(5,TimeUnit.MINUTES)
            .addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
            .addInterceptor {
                //val token = SPUtils.getInstance().getString(Cons.SP_TOKEN)
                val request = it.request().newBuilder().addHeader(Cons.HEADER_TOKEN,"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJhdXRoMCIsImV4cCI6MTczMTA0OTkwMCwidXNlcm5hbWUiOiIxNTIzMTI4MjY2OCJ9.eND_vym-MNLWt5A7iPt8dDJZ167Ep-qUq0tKg-e5Gf8").build()
                it.proceed(request)
            }
            .build()
        fun getRetrofit():Retrofit{
            val retrofit = Retrofit.Builder()
                .client(client)
                .baseUrl(Cons.BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build()
            return retrofit
        }
    }
}